package com.ccrfid.rmc6.lbservice3.client;

import com.ccrfid.rmc6.appconfig.websocket.MsgEntity;

import java.io.IOException;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

public abstract class WebClient {
    private String clientId;
    private String userAccount;
    private List<String> clientIpAddrs;
    private Set<Long> locationIdSet;    //客户端关注的区域列表
    private Long doorId;                //客户端关注的二道门

    public WebClient(String clientId, String userAccount, List<String> clientIpAddrs) {
        this.clientId = clientId;
        this.userAccount = userAccount;
        this.clientIpAddrs = clientIpAddrs;
        this.locationIdSet = ConcurrentHashMap.newKeySet();
    }

    public String getClientId() {
        return clientId;
    }

    public void setClientId(String clientId) {
        this.clientId = clientId;
    }

    public String getUserAccount() {
        return userAccount;
    }

    public void setUserAccount(String userAccount) {
        this.userAccount = userAccount;
    }

    public List<String> getClientIpAddrs() {
        return clientIpAddrs;
    }

    public void setClientIpAddrs(List<String> clientIpAddrs) {
        this.clientIpAddrs = clientIpAddrs;
    }

    public Set<Long> getLocationIdSet() {
        return locationIdSet;
    }

    public void setLocationIdSet(Set<Long> locationIdSet) {
        this.locationIdSet = locationIdSet;
    }

    public void addLocation(Long locationId) {
        this.locationIdSet.add(locationId);
    }

    public void updateLocations(Set<Long> locationIdSet) {
        this.locationIdSet.clear();
        this.locationIdSet.addAll(locationIdSet);
    }

    public Long getDoorId() {
        return doorId;
    }

    public void setDoorId(Long doorId) {
        this.doorId = doorId;
    }

    public abstract void postMsg(String msgType, String msgContent) throws IOException;

    public abstract void postMsg(MsgEntity<?> msgEntity) throws IOException;

    public abstract void closeConnection();

    @Override
    public String toString() {
        return "WebClient{" +
                "clientId='" + clientId + '\'' +
                ", userAccount='" + userAccount + '\'' +
                ", clientIpAddrs=" + clientIpAddrs +
                ", locationIdSet=" + locationIdSet +
                '}';
    }
}
